/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tpgen.grammar;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author shanki
 */
public class Sequence implements Symbol, Iterable<Symbol> {
    private List<Symbol> symbols    = new ArrayList<Symbol>();
    
    public Sequence(Symbol ...symbols) {
        this.symbols.addAll(Arrays.asList(symbols));
    }

    @Override
    public boolean isUsable() {
        for (Symbol symbol : symbols) {
            if (symbol.isUsable() == false) {
                return false;
            }
        }
        
        return symbols.isEmpty() == false;
    }

    @Override
    public Iterator<Symbol> iterator() {
        return symbols.iterator();
    }

    @Override
    public Collection<Symbol> expand(Context context) {
        return symbols;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Sequence) {
            Sequence other = (Sequence)obj;
            
            return this.symbols.equals(other.symbols);
        } else {
            return false;
        }
    } 

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (this.symbols != null ? this.symbols.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "/seq/";
    }    

    @Override
    public String toUserString() {
        return "";
    }
}
